#!/usr/bin/env bash

## Electron apps do not have auto-update for deb packages.
## Instead we add our apt repo as a post-install step. The user can then get app updates
## via their typical apt update workflow.

# Link the binary into global /usr/bin
ln -sf '/opt/${productFilename}/${executable}' '/usr/bin/${executable}'

# SUID chrome-sandbox for Electron 5+
chmod 4755 '/opt/${productFilename}/chrome-sandbox' || true

update-mime-database /usr/share/mime || true
update-desktop-database /usr/share/applications || true

# APT_SOURCE_PARTS is where apt looks for source.list files (i.e. /etc/apt/sources.list.d/)
eval $(apt-config shell APT_SOURCE_PARTS Dir::Etc::sourceparts/d)
APT_SOURCE_PART=${APT_SOURCE_PARTS}foxglove-studio.list

# APT_TRUSTED_PARTS is where apt looks for gpg keys for repos (i.e. /etc/apt/trusted.gpg.d/)
eval $(apt-config shell APT_TRUSTED_PARTS Dir::Etc::trustedparts/d)
APT_TRUSTED_PART=${APT_TRUSTED_PARTS}foxglove.gpg

gpg --dearmor > $APT_TRUSTED_PART <<PUBKEY
-----BEGIN PGP PUBLIC KEY BLOCK-----

mQENBGA4HUsBCADijKmTrSmvnAiHJvsoUVLnJ2Y73acLwvodHVSrQD9bWFjxZcXD
HUFw1ZUxwisbBr9E34qeb+erfhgT4CwxCtrigp+f8Fwhbdc4hXX/ACuVbNzrV0Fw
0H5+3YSvA+aoZuvTy73Tl5eWx/m+N/1GBMtL7GoibVVHLJxVNoM9KY/KgnjD5j0Y
hgZgwytHifVA5bkxi0LBzexwBkuensFoGKylSBvY7b92DjmR+/u6gcnJVx2hC5/b
HevH9HNcc4LaC3/7/v549sw3twu1lIspo4F1pKs3llvYC4PY6rkvT/o49+XewdxN
zbxmscdBdYnCuWf72uncV6uvTcp2EiPOgkOfABEBAAG0M0ZveGdsb3ZlIFNvZnR3
YXJlIFBhY2thZ2luZyA8c2VjdXJpdHlAZm94Z2xvdmUuZGV2PokBTgQTAQgAOBYh
BLPRAZFA/IcSJDoWhDE0Jwlm6O/XBQJgOB1LAhsDBQsJCAcCBhUKCQgLAgQWAgMB
Ah4BAheAAAoJEDE0Jwlm6O/X2r4H/2DlAnMtv+DPw9cbUAEj2iqnZkYKGb4T1iMb
ijfLFlrpB6aiQ2P3DV3mBrVVaP+Hs30/MvH2GB9jJdUk22b+OJwVUpzeevWauKxz
cF4cGmEUzriwfTk50+Lo0pHSlbx0ISv/aLHxnOUV4EfjOkLNAii8YgcHCI1WDQYR
QHK8XHqosTwgYCw4I3+NBVKPGUx5bo7sIxF5qSWiRq0U6UkflrRk7kmNacbng1rm
6S6PM8iLZ1DdZqWfSnGJNuLX6Fn/TXZP06twCWeh2mpZwETzvUD92hxUVFuFWNKV
9B45plmZv4N79Vz/ywhI8YiVjcjF924jhu8Nk9PdAu/0yZnM2GQ=
=T+L2
-----END PGP PUBLIC KEY BLOCK-----
PUBKEY

echo "### THIS FILE IS AUTOMATICALLY GENERATED ###
deb [arch=amd64,arm64] https://apt.foxglove.dev/studio stable main" > $APT_SOURCE_PART
